package com.bocai.eelly.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.eelly.R;
import com.bocai.eelly.bean.FactoryListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/30.
 */
public class FindFactoryAdp extends BaseAdapter {
    private Context context;
    private List<FactoryListBean.Data> datas = new ArrayList<>();

    public FindFactoryAdp(Context context, List<FactoryListBean.Data> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.find_factory_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tvFindFactoryCompany.setText(datas.get(position).getCompany());
        viewHolder.tvFindFactoryStyle.setText("擅长款式: "+datas.get(position).getStyle());
        viewHolder.tvFindFactoryCity.setText(datas.get(position).getCity());
        viewHolder.tvFindFactoryTime.setText("空挡工时数: "+datas.get(position).getFree_days());
        return convertView;
    }



    class ViewHolder {
        @Bind(R.id.tv_find_factory_company)
        TextView tvFindFactoryCompany;
        @Bind(R.id.tv_find_factory_city)
        TextView tvFindFactoryCity;
        @Bind(R.id.tv_find_factory_style)
        TextView tvFindFactoryStyle;
        @Bind(R.id.tv_find_factory_time)
        TextView tvFindFactoryTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
